<template>
    <!--选择车位的 弹框-->
    <el-dialog title="选择停车位" append-to-body :visible.sync="visible" width="900px">
        <el-form ref="seatForm" :model="form" inline label-width="100px">
            <el-form-item label="停车场" prop="parkingId">
                <el-select filterable v-model="form.parkingId" placeholder="请选择停车场">
                    <el-option v-for="item in parkingList" :key="item.id" :label="item.parkingCode" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="停车位编号" prop="carCode">
                <el-input v-model="form.carCode" placeholder="请输入停车位编号" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <JTable v-loading="loading" :data="seatList" height="400">
            <el-table-column label="停车场ID" align="center" prop="parkingId" />
            <el-table-column label="停车位ID" align="center" prop="id" />
            <el-table-column label="停车场编码" align="center" prop="parkingCode" />
            <el-table-column label="停车位编码" align="center" prop="carCode" />
            <el-table-column label="车位类型" align="center" prop="type">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.park_space_type" :value="scope.row.type" />
                </template>
            </el-table-column>
            <el-table-column label="车位状态" align="center" prop="status">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.park_space_status" :value="scope.row.status" />
                </template>
            </el-table-column>
            <el-table-column label="面积" align="center" prop="area" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button type="primary" @click="handleSelect(scope.row)">选择</el-button>
                </template>
            </el-table-column>
        </JTable>
        <pagination v-show="total > 0" :total="total" :page.sync="form.page" :limit.sync="form.limit" @pagination="getList" />
    </el-dialog>
</template>
<script>
import { getParkdingSeatList } from '@/api/parking/parkingSeat.js';
import { listParking } from '@/api/parking/areaManage.js';
export default {
    dicts: ['park_space_type', 'park_space_status'],
    // props: {},
    data() {
        return {
            // 遮罩层
            loading: true,
            visible: false,
            total: 0,
            seatList: [],
            parkingList: [],
            form: {
                page: 1,
                limit: 10,
                parkingId: '',
                carCode: '',
                status: 0,
            },
        };
    },
    methods: {
        init() {
            this.visible = true;
            this.$nextTick(() => {
                this.$refs['seatForm'].resetFields();
                this.getList();
                this.getParkingList();
            });
        },
        // 获取车位列表
        getList() {
            this.loading = true;
            getParkdingSeatList(this.form).then(response => {
                this.loading = false;
                this.seatList = response.data.list;
                this.total = response.data.total;
            });
        },

        /** 停车场管理列表 */
        getParkingList() {
            listParking().then(response => {
                this.parkingList = response.data.list;
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.form.page = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm('seatForm');
            this.form.page = 1;
            this.getList();
        },
        // 选择了一个 车位
        handleSelect(row) {
            this.visible = false;
            this.$emit('handleSelectSeatInfo', row);
        },
    },
};
</script>
